//
//  SetPasswordVC.m
//  BigJoy
//
//  Created by Rowling on 2017/7/3.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "SetPasswordVC.h"

@interface SetPasswordVC ()
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *yaoqingmaTextField;

@end

@implementation SetPasswordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUP];
}
-(void)setUP {
    @weakify(self);
    [[[self.passwordTextField rac_textSignal] map:^id _Nullable(NSString * _Nullable value) {
        if (value.length >= 20) {
            return [value substringWithRange:NSMakeRange(0, 20)];
        }
        return value;
    }] subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        NSLog(@"%@",x);
        self.passwordTextField.text = x;
    }];
}



- (IBAction)loginAndRegisterButtonClick:(id)sender {
    if (self.passwordTextField.text.length < 6) {
        [Apputil showError:@"密码不能小于6位"];
        return;
    }
    [Apputil showMessage:@"请求中"];
    NSDictionary * dic = @{
                           @"phone" : self.phoneStr,
                           @"pwd"   : self.passwordTextField.text,
                           @"be_invited" : self.yaoqingmaTextField.text,
                           @"registration_id" : @"UUID"
                           };

    [WYNetTool GET_Urlstring:RegisterUrl parameters:dic success:^(id responseObject) {
        if ([responseObject[@"code"] longLongValue] == 1) {
            [Apputil dismiss];
            [Apputil showMessage:@"注册成功,开始登陆"];
            [UserTool LoginWithAC:self.phoneStr pwd:self.passwordTextField.text block:^(BOOL suceess){
                if (suceess) {
                    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
                }
            }];
        }
    } fail:^(id error) {
        
    }];
}


@end
